﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software components that provide 
// support for localization. This library enables you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace SLS.ExClassLib.Loc
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Represents a token of a <see cref="DynamicResource"/>.
    /// </summary>
    public class DynamicResourceToken
    {
        //Fields

        public volatile bool IsValide;

        //Constructors

        /// <summary>
        /// Creates a new instance of the <see cref="DynamicResourceToken"/> class.
        /// </summary>
        /// <param name="resourceID">Specifies the identifier of the resource.</param>
        /// <param name="resourceID">Specifies the language.</param>
        /// <exception cref="ArgumentException">
        /// Thrown whether <paramref name="resourceID"/> parameter is either null or equals to white space.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown whether <paramref name="language"/> parameter is null.
        /// </exception>
        internal DynamicResourceToken(String resourceID, Language language)
        {
            if (String.IsNullOrEmpty(resourceID))
            {
                throw new ArgumentException("resourceID parameter shouldn't be either null or equals at white space.");
            }
            if (language == null)
            {
                throw new ArgumentNullException("language parameter shouldn't be either null.");
            }
            this.ResourceID = resourceID;
            this.Language = language;
            this.IsValide = true;
        }

        //Properties

        /// <summary>
        /// Gets resource's identifier.
        /// </summary>
        public String ResourceID { get; private set; }

        /// <summary>
        /// Gets language.
        /// </summary>
        public Language Language { get; private set; }

        /// <summary>
        /// Gets/Sets the value.
        /// </summary>
        public Object Value { get; set; }

        /// <summary>
        /// Gets true whether the text is localized, false otherwise.
        /// </summary>
        public bool IsLocalized { get; internal set; }

        //Methods

        /// <summary>
        /// Serves as a hash function for <see cref="DynamicResource"/> type.
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return this.ResourceID.GetHashCode();
        }

        /// <summary>
        /// Determines whether the specified <see cref="DynamicResource"/> is equals to the current <see cref="DynamicResource"/>.
        /// </summary>
        /// <param name="obj">Instance.</param>
        /// <returns>True whether the input instance is equals to the current instance otherwise false.</returns>
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return true;
            }
            else if ((obj == null) || (obj.GetType() != this.GetType()))
            {
                return false;
            }
            DynamicResourceToken instance = obj as DynamicResourceToken;
            return (instance.ResourceID.Equals(this.ResourceID) && (instance.Language.Code.Equals(this.Language.Code)));
        }
    }
}